import java.awt.Color;
import java.util.ArrayList;

import uchicago.src.reflector.RangePropertyDescriptor;
import uchicago.src.sim.analysis.DataSource;
import uchicago.src.sim.analysis.OpenSequenceGraph;
import uchicago.src.sim.analysis.Sequence;
import uchicago.src.sim.engine.BasicAction;
import uchicago.src.sim.engine.Schedule;
import uchicago.src.sim.engine.SimInit;
import uchicago.src.sim.engine.SimModelImpl;
import uchicago.src.sim.gui.ColorMap;
import uchicago.src.sim.gui.DisplaySurface;
import uchicago.src.sim.gui.Object2DDisplay;
import uchicago.src.sim.gui.Value2DDisplay;
import uchicago.src.sim.util.SimUtilities;

/**
 * Class that implements the simulation model for the rabbits grass simulation. This is the first class which needs to be setup in order to run Repast simulation. It manages the entire RePast
 * environment and the simulation.
 * 
 * @author
 */

public class RabbitsGrassSimulationModel extends SimModelImpl {
	private static final int NUMAGENTS = 100;
	private static final int WORLDXSIZE = 40;
	private static final int WORLDYSIZE = 40;
	private static final int TOTALMONEY = 1000;

	private Schedule schedule;
	private RabbitsGrassSimulationSpace cdSpace;
	private DisplaySurface displaySurf;

	private int numAgents = NUMAGENTS;
	private int worldXSize = WORLDXSIZE;
	private int worldYSize = WORLDYSIZE;
	private int money = TOTALMONEY;

	/** 
	 * Reset button
	 */
	public void setup() {
		System.out.println("Running setup");
		cdSpace = null;

		if (displaySurf != null) {
			displaySurf.dispose();
		}
		displaySurf = null;

		displaySurf = new DisplaySurface(this, "Carry Drop Model Window 1");
		registerDisplaySurface("Carry Drop Model Window 1", displaySurf);
	}

	/**
	 * Initialize button
	 */
	public void begin() {
		buildModel();
		buildSchedule();
		buildDisplay();

		displaySurf.display();
	}

	private void buildModel() {
		System.out.println("Running BuildModel");
		cdSpace = new RabbitsGrassSimulationSpace(worldXSize, worldYSize);
		cdSpace.spreadMoney(money);
	}

	private void buildSchedule() {
		System.out.println("Running BuildSchedule");
	}

	private void buildDisplay() {
		System.out.println("Running BuildDisplay");
		ColorMap map = new ColorMap();

		for (int i = 1; i < 16; i++) {
			map.mapColor(i, new Color((int) (i * 8 + 127), 0, 0));
		}
		map.mapColor(0, Color.white);

		Value2DDisplay displayMoney = new Value2DDisplay(cdSpace.getCurrentMoneySpace(), map);
		displaySurf.addDisplayable(displayMoney, "Money");
	}

	public String[] getInitParam() {
		String[] initParams = { "NumAgents", "WorldXSize", "WorldYSize", "Money" };
		return initParams;
	}

	/*
	 * Get name of simulation model
	 * 
	 * @see uchicago.src.sim.engine.SimModel#getName()
	 */
	public String getName() {
		return "Rabbit Grass";
	}

	public Schedule getSchedule() {
		// TODO Auto-generated method stub
		return null;
	}

	public int getNumAgents() {
		return numAgents;
	}

	public void setNumAgents(int na) {
		numAgents = na;
	}

	public int getWorldXSize() {
		return worldXSize;
	}

	public void setWorldXSize(int wxs) {
		worldXSize = wxs;
	}

	public int getWorldYSize() {
		return worldYSize;
	}

	public void setWorldYSize(int wys) {
		worldYSize = wys;
	}

	public int getMoney() {
		return money;
	}

	public void setMoney(int i) {
		money = i;
	}

	public static void main(String[] args) {
		System.out.println("Rabbit skeleton");
		SimInit init = new SimInit();
		RabbitsGrassSimulationModel model = new RabbitsGrassSimulationModel();
		init.loadModel(model, "", false);
	}
}
